package com.chb.common;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author CHB
 * @createTime 2022-8-23 16:44
 */
@Getter
@AllArgsConstructor
public enum ResultCode {

    /**
     * ok
     */
    SUCCESS (2000,"OK") ,
    /**
     * 服务器错误
     */
    ERROR (5000,"服务器开小差了"),
    /**
     * 资源未找到
     */
    NO_RESOURCE (404,"资源未找到"),
    /**
     * 请求超时
     */
    TIME_OUT_REQUEST(5040,"请求超时"),
    /**
     * 响应超时
     */
    TIME_OUT_RESPONSE (5040,"响应超时"),
    /**
     * 参数错误
     */
    PARAMETER_ERROR (4010,"参数错误"),
    /**
     * 客户端错误
     */
    CLIENT_ERROR (4010,"客户端错误"),
    /**
     * 没权限
     */
    PERMISSION_DENIED (4030,"没权限")
    ;

    private final int code;
    private final String message;

    public static String getNameByCode(int code){
        for (ResultCode resultCode : ResultCode.values()) {
            if(resultCode.getCode() == code){
                return resultCode.getMessage();
            }
        }
        return "";
    }
}
